package com.lh1010.s3.controller;

import com.lh1010.s3.service.TestService;
import com.lh1010.s3.vo.McUserVo;
import com.zielsmart.web.basic.exception.ValidateException;
import com.zielsmart.web.basic.vo.ResultVo;
import io.swagger.v3.oas.annotations.media.Content;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/test", consumes = MediaType.APPLICATION_JSON_VALUE)
public class TestController {
    @Resource
    TestService testService;

    @PostMapping(value = "test1")
    public ResultVo<String> test1() {
        //return "test1";
        return ResultVo.ofFail("test1");
    }

    @PostMapping(value="getUsers")
    @io.swagger.v3.oas.annotations.parameters.RequestBody(content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE))
    public ResultVo<List<McUserVo>> getUsers(@RequestBody McUserVo searchVo) {
        return ResultVo.ofSuccess(testService.getUsers(searchVo));
    }

    @PostMapping(value="updateUser")
    @io.swagger.v3.oas.annotations.parameters.RequestBody(content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE))
    public ResultVo<String> updateUser(@RequestBody McUserVo mcUserVo) throws ValidateException {
        testService.updateUser(mcUserVo);
        return ResultVo.ofSuccess();
    }
}
